﻿Imports QuanLyBanChau.LoaiChau_bus
Public Class frmQLLoaiChau

    Private Sub frmQLLoaiChau_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As DataTable = New DataTable()
        dt = Get_LoaiChauBUS()
        gvDSLoai.DataSource = dt
    End Sub

    Private Sub gvDSLoai_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gvDSLoai.CellClick
        txtMaLoai.Text = gvDSLoai.CurrentRow.Cells(0).Value.ToString()
        txtTenLoai.Text = gvDSLoai.CurrentRow.Cells(1).Value.ToString()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        Dim Loai As LoaiChau = New LoaiChau()
        Loai.Maloai = txtMaLoai.Text.ToString()
        Loai.Tenloai = txtTenLoai.Text.ToString()
        Insert_LoaiChauBUS(Loai)
        frmQLLoaiChau_Load(sender, e)
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim XacNhan As DialogResult = MessageBox.Show("Bạn có chắc chắn muốn xóa loại này không?", "Xóa?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
        If XacNhan = DialogResult.OK Then
            Dim maLoai As String
            maLoai = gvDSLoai.CurrentRow.Cells(0).Value.ToString()
            Delete_LoaiChauBUS(maLoai)
            gvDSLoai.Rows.Remove(gvDSLoai.CurrentRow)
        End If
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        Dim Loai As LoaiChau = New LoaiChau()
        Loai.Maloai = txtMaLoai.Text.ToString()
        Loai.Tenloai = txtTenLoai.Text.ToString()
        Update_LoaiChauBUS(Loai)
        frmQLLoaiChau_Load(sender, e)
    End Sub
End Class